package mysql

import (
	"github.com/astaxie/beego/orm"
)

type Device struct {
	Id           int    `orm:"Column(ID)"`
	StoreId      string `orm:"Column(StoreId)"`
	DeviceNameId string `orm:"Column(DeviceNameId)"`
	IPaddr       string `orm:"Column(IPaddr)"`
	Enabled      int    `orm:"Column(Enabled)"`
	DeviceType   string `orm:"Column(DeviceType)"`
	Online       int    `orm:"Column(Online)"`
	UpdateTime   string `orm:"Column(UpdateTime)"`
}

func (u *Device) TableName() string {
	return DeviceTBName()
}

func InsertDevice(d Device) (int64, error) {
	o := orm.NewOrm()
	//o.Using("default")
	return o.InsertOrUpdate(&d)
}

func FindAllDevice() (*[]Device, error) {
	qs := orm.NewOrm().QueryTable(DeviceTBName())
	devices := new([]Device)
	_, err := qs.All(devices)
	return devices, err
}
